package com.util.sdk;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.codec.binary.Base64;

public class UploadTest {
	
	
	
	public static String doTest(String urlStr,String postData) {
		String reString = "";
		try {	
			//用于注册的用户名密码问题答案临时变量
		//	String urlstr="http://log.150hi.com/upload/up.php?88888";
			URL url = new URL(urlStr);

			URLConnection conn = url.openConnection();
			//这里是关键，表示我们要向链接里输出内容
			conn.setDoOutput(true);
			//获得连接输出流　
			OutputStreamWriter out= new OutputStreamWriter(conn.getOutputStream());

			out.write(postData);
			out.flush();
			out.close();
			
			//到这里已经完成了，不过我们还是看看返回信息吧
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line = null;

			int lineNum = 1 ;
			while( ( line=reader.readLine() ) != null ) {
				
			//	System.out.println(line);
				reString += line;
			}
		} catch (Exception e) {

			e.printStackTrace();
		}
		return reString;
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
		
		try {	
			//用于注册的用户名密码问题答案临时变量
			String urlstr="http://log.150hi.com/upload/up.php?88888";
			URL url = new URL(urlstr);

			URLConnection conn = url.openConnection();
			//这里是关键，表示我们要向链接里输出内容
			conn.setDoOutput(true);
			//获得连接输出流　
			OutputStreamWriter out= new OutputStreamWriter(conn.getOutputStream());

			out.write("testtesttest");
			out.flush();
			out.close();
			
			//到这里已经完成了，不过我们还是看看返回信息吧，他的注册返回信息也在此页面　
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line = null;
		
			
			int lineNum = 1 ;
			while( ( line=reader.readLine() ) != null ) {
				
				System.out.println(line);
			}
			
		} catch (Exception e) {

			e.printStackTrace();
		}
	}
}
